<!-- 上拉加载区域 -->
<template>
  <view
    class="mescroll-upwarp"
    :style="{ 'background-color': mOption.bgColor, color: mOption.textColor }"
  >
    <!-- 加载中 (此处不能用v-if,否则android小程序快速上拉可能会不断触发上拉回调) -->
    <view v-show="isUpLoading">
      <view
        class="upwarp-progress mescroll-rotate"
        :style="{ 'border-color': mOption.textColor }"
      ></view>
      <view class="upwarp-tip">{{ mOption.textLoading || "加载中..." }}</view>
    </view>
    <!-- 无数据 -->
    <block class="">
      <view v-if="isUpNoMore" class="upwarp-nodata">
        <text>{{ mOption.textNoMore || "没有更多数据啦~" }}</text>
      </view>
    </block>
  </view>
</template>

<script setup lang="ts">
import { computed, defineProps } from "vue";
const props = defineProps({
  option: Object, // up的配置项
  type: Number, // 上拉加载的状态：0（loading前），1（loading中），2（没有更多了）
  list: {
    type: Array,
    default: () => [],
  },
});

// 支付宝小程序需写成计算属性,prop定义default仍报错
const mOption = computed(() => {
  return props.option || {};
});
// 加载中
const isUpLoading = computed(() => {
  return props.type === 1;
});
// 没有更多了
const isUpNoMore = computed(() => {
  return props.type === 2;
});
</script>

<style lang="scss" scoped>
/* 上拉加载区域 */
.mescroll-upwarp {
  box-sizing: border-box;
  min-height: 80rpx;
  padding: 30rpx 0;
  text-align: center;
  clear: both;
}

/*提示文本 */
.mescroll-upwarp .upwarp-tip,
.mescroll-upwarp .upwarp-nodata {
  display: inline-block;
  font-size: 28rpx;
  vertical-align: middle;
  /* color: gray; 已在style设置color,此处删去*/
}

.mescroll-upwarp .upwarp-tip {
  margin-left: 16rpx;
}

/*旋转进度条 */
.mescroll-upwarp .upwarp-progress {
  display: inline-block;
  width: 32rpx;
  height: 32rpx;
  border-radius: 50%;
  border: 2rpx solid gray;
  border-bottom-color: transparent !important;
  /*已在style设置border-color,此处需加 !important*/
  vertical-align: middle;
}

/* 旋转动画 */
.mescroll-upwarp .mescroll-rotate {
  animation: mescrollUpRotate 0.6s linear infinite;
}

@keyframes mescrollUpRotate {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}
.upwarp-nodata {
  display: flex;
  align-items: center;
  justify-content: center;
  & > text {
    margin: 0 30rpx;
    font-weight: 300;
    color: #666666;
    font-size: 22rpx;
  }
  &::before {
    content: " ";
    display: inline-block;
    flex: 1;
    height: 1rpx;
    border-bottom: 2rpx solid #dcdcdc;
  }
  &::after {
    content: " ";
    display: inline-block;
    height: 1rpx;
    flex: 1;
    border-bottom: 2rpx solid #dcdcdc;
  }
}
</style>
